﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

namespace Safover.LidarCollector.Core
{
    internal class OpticalMaserOpenedStateController : BaseOpticalMaserController
    {
        public override OpticalMaserStatus OpticalMaserStatus => OpticalMaserStatus.Opened;

        public override bool CanClose => true;

        public OpticalMaserOpenedStateController(OpticalMaserDevice device) : base(device)
        { }

        public override bool TryClose()
        {
            try
            {
                Device.CloseSerialPort();
                return true;
            }
            finally
            {
                SetStatus(OpticalMaserStatus.Closed);
            }
        }

        public override void TryStartLazar()
        {
            var success = Device.StopLasar();
            if (success)
            {
                SetStatus(OpticalMaserStatus.Irradiating);
            }
        }

        public override void TryErrorReset()
        {
            Device.ErrorReset();
        }

    }
}